<?php
	/**
	 * 获取财富榜
	 */
    class Wealthboard extends APIBase {
		
		public $tag = "Wealthboard";
    	public $isLogin = false;
		
		public function before() {
			$this->initCacheRedis();
			return true;
		}
		public function logic() {
			//$ann = $this->cache_redis->hMGet("ha:*", array("id","title","content","image_url"));
			$userid = $this->param['playerID'];
			$wealthboard = $this->cache_redis->keys("hWealthboard:*");
			$count = count($wealthboard);
			$result = array();
			$data = array();
			if ($count) {
				for($i=0;$i<$count;$i++){
				    $list = $this->cache_redis->hGetAll("hWealthboard:".$i);
					if($list['id']==$userid){
                        $data = array('point'=>$list['coin'],'rank'=>$list['num']); 
					}
                    if($i<=10){					
				        $result[] = $list;
                  	}			  
				}
                $selfdata = array();
				if(empty($data)){
					$selfdata[]= array('point'=>'0','rank'=>'未入围');
				}elseif($data['rank']>10){
					$selfdata[]= array('point'=>$data['point'],'rank'=>'未入围');
				}elseif($data['rank']<=10){
					
					$selfdata[]= array('point'=>$data['point'],'rank'=>$data['rank']);
				}

				$this->returnData(array_merge($result,$selfdata));
			} else {
				$this->returnError(301,"对不起，暂无财富排行榜！");
			}

		}
		
        public function after() {
			$this->deinitCacheRedis();
		}
    }
?>
